package com.macro.mall.portal.config;

import cn.hutool.core.lang.Assert;
import com.macro.mall.common.exception.ApiException;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;

import java.util.List;

/**
 * @author <a href="https://github.com/binarywang">Binary Wang</a>
 */
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "wx.miniapp")
public class WxMaProperties {

    private List<Config> configs;

    public static class Config {
        /**
         * 设置微信小程序的appid
         */
        private String appid;

        /**
         * 设置微信小程序的Secret
         */
        private String secret;

        /**
         * 设置微信小程序消息服务器配置的token
         */
        private String token;

        /**
         * 设置微信小程序消息服务器配置的EncodingAESKey
         */
        private String aesKey;

        /**
         * 消息格式，XML或者JSON
         */
        private String msgDataFormat;

        /**
         * offerId
         */
        private String offerId;


        /**
         * env
         */
        private Integer env;


        /**
         * 现网AppKey
         */
        private String productAppKey;

        /**
         * 沙箱AppKey
         */
        private String sandboxAppKey;

        /**
         * 微信小程序的微信媒资小程序ID
         */
        private String correlationAppid;



        public String getAppid() {
            return appid;
        }

        public void setAppid(String appid) {
            this.appid = appid;
        }

        public String getSecret() {
            return secret;
        }

        public void setSecret(String secret) {
            this.secret = secret;
        }

        public String getToken() {
            return token;
        }

        public void setToken(String token) {
            this.token = token;
        }

        public String getAesKey() {
            return aesKey;
        }

        public void setAesKey(String aesKey) {
            this.aesKey = aesKey;
        }

        public String getMsgDataFormat() {
            return msgDataFormat;
        }

        public void setMsgDataFormat(String msgDataFormat) {
            this.msgDataFormat = msgDataFormat;
        }


        public String getOfferId() {
            return offerId;
        }

        public void setOfferId(String offerId) {
            this.offerId = offerId;
        }

        public Integer getEnv() {
            return env;
        }

        public void setEnv(Integer env) {
            this.env = env;
        }

        public String getProductAppKey() {
            return productAppKey;
        }

        public void setProductAppKey(String productAppKey) {
            this.productAppKey = productAppKey;
        }

        public String getSandboxAppKey() {
            return sandboxAppKey;
        }

        public void setSandboxAppKey(String sandboxAppKey) {
            this.sandboxAppKey = sandboxAppKey;
        }

        public String getCorrelationAppid() {
            return correlationAppid;
        }

        public void setCorrelationAppid(String correlationAppid) {
            this.correlationAppid = correlationAppid;
        }
    }

    public List<Config> getConfigs() {
        return configs;
    }

    public void setConfigs(List<Config> configs) {
        this.configs = configs;
    }

    public Config getConfigByAppid(String targetAppid) {
        for (Config config : configs) {
            if (config.getAppid().equals(targetAppid)) {
                return config;
            }
        }

        throw new ApiException("APPID信息有误！"+targetAppid);
    }
}
